// 笔试强训day22：装箱问题

#include <iostream>
#include <vector>
using namespace std;

int main() {
    int V = 0, n = 0;
    cin >> V >> n;
    vector<int> vs(n + 1, 0);
    for(int i = 1; i <= n; i++)
    {
        cin >> vs[i];
    }

    vector<vector<int>> dp(n + 1, vector<int>(V + 1, 0));
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= V; j++)
        {
            if(j >= vs[i])
                dp[i][j] = max(dp[i - 1][j - vs[i]] + vs[i], dp[i - 1][j]);
            else
                dp[i][j] = dp[i - 1][j];
        }
    }
    cout << V - dp[n][V] << endl;
}